Factory method for creating a new object name, mapping any checked {@link MalformedObjectNameException} to
a runtime exception ({@link IllegalArgumentException})
@param pName name to convert
@return the created object name
558561
public static ObjectName newObjectName(String pName) {
        try {
            return new ObjectName(pName);
        } catch (MalformedObjectNameException e) {
            throw new IllegalArgumentException("Invalid object name " + pName,e);
        }
    }
197465
private static String buildObjectName(final Object object, final String... parameters) {
		final StringBuilder objectName = new StringBuilder();
		objectName.append(object.getClass().getPackage().getName());
		objectName.append(":type=");
		objectName.append(object.getClass().getName());
		if (parameters.length > 0) {
			objectName.append('(');
			for (final String parameter : parameters)
				objectName.append(parameter).append(',');
			objectName.deleteCharAt(objectName.length() - 1);
			objectName.append(')');
		}
		return objectName.toString();
	}

	/**
	 * Private constructor.
	 */
	private MBeanRegisterUtil() {
		throw new IllegalAccessError("Can't instantiate.");
	}
}
673482
public static <T> ObjectName getObjectName(final Class<T> clazz)
        {
        final String domain = clazz.getPackage().getName();
        final String className = clazz.getSimpleName();
        final String objectName = domain+":type="+className;
        LOG.debug("Returning object name: {}", objectName);
        try
            {
            return new ObjectName(objectName);
            }
        catch (final MalformedObjectNameException e)
            {
            // This should never, ever happen.
            LOG.error("Invalid ObjectName: "+objectName, e);
            throw new RuntimeException("Could not create ObjectName?", e);
            }
        }
654194
public ObjectName createCustomComponentMBeanName(final String type, final String name) {
    ObjectName result = null;
    String tmp = jmxDomainName + ":" +
                 "type=" + sanitizeString(type) +
                 ",name=" + sanitizeString(name);
    try {
      result = new ObjectName(tmp);
    } catch (MalformedObjectNameException e) {
      error("Couldn't create ObjectName from: " + type + " , " + name);
    }
    return result;
  }
346996
private static ObjectName getObjectName(String name) {

		ObjectName mBeanName = null;
		try {
			mBeanName = new ObjectName(name);
		} catch (MalformedObjectNameException | NullPointerException e) {
			throw new JmxConfigException(e);
		}

		return mBeanName;
	}
637029
public static Object newInstance(String name) {
        try {
            return forName(name).newInstance();
        } catch (InstantiationException e) {
            throw new IllegalStateException(e.getMessage(), e);
        } catch (IllegalAccessException e) {
            throw new IllegalStateException(e.getMessage(), e);
        }
    }
65536
public Object createObject(String className, Class clazz) throws ClassNotFoundException {
        Object object;
        try {
            object = clazz.newInstance();

        } catch (InstantiationException ie) {
            String info = "Could not create " + description + " object: " + className
                    + ". Could not access object constructor: ";
            info += ie.getMessage();
            throw new ClassNotFoundException(info, ie);

        } catch (IllegalAccessException iae) {
            String info = "Could not create " + description + " object: " + className
                    + ". Could not instantiate object. Does the object classname refer to an abstract class, "
                    + "an interface or the like?: ";
            info += iae.getMessage();
            throw new ClassNotFoundException(info, iae);

        } catch (ClassCastException cce) {
            String info = "Could not create " + description + " object: " + className
                    + ". The specified object classname does not refer to the proper type: ";
            info += cce.getMessage();
            throw new ClassNotFoundException(info, cce);
        }

        return object;
    }
1138293
@VisibleForTesting
	static String createIncompletePartObjectNamePrefix(String objectName) {
		checkNotNull(objectName);

		final int lastSlash = objectName.lastIndexOf('/');
		final String parent;
		final String child;

		if (lastSlash == -1) {
			parent = "";
			child = objectName;
		} else {
			parent = objectName.substring(0, lastSlash + 1);
			child = objectName.substring(lastSlash + 1);
		}
		return parent + (child.isEmpty() ? "" : '_') + child + "_tmp_";
	}
830881
@Action(
            semantics = SemanticsOf.IDEMPOTENT,
            command = CommandReification.ENABLED
    )
    public SomeCommandAnnotatedObject changeName(
            @ParameterLayout(named = "New name")
            final String newName) {
        setName(newName);
        return this;
    }
854534
public Object create(String name, Object... args)
    throws ClassNotFoundException,
           NoSuchMethodException,
           IllegalAccessException,
           InstantiationException,
           InvocationTargetException
    {
//StringBuilder sb = new StringBuilder("DefaultObjectFactory.create(").append(name).append(',');
//for (Object arg: args) {
//sb.append(arg.getClass().getName()).append(' ');
//}
//sb.append(')');
//System.err.println(sb);
        try {
            Class<?> type = Class.forName(name);
/*
            Constructor<?>[] constructors = type.getConstructors();
            for (Constructor<?> constructor: constructors) {
                Class<?>[] ptypes = constructor.getParameterTypes();
                if (ptypes.length == args.length) {
                    try {
                        return constructor.newInstance(args);
                    } catch (IllegalArgumentException x) {
                        // ignore and try the next one
                    } catch (IllegalAccessException x) {
                        throw x;
                    } catch (InstantiationException x) {
                        throw x;
                    } catch (InvocationTargetException x) {
                        throw x;
                    }
                }
            }
            throw new NoSuchMethodException("Can't locate a desired constructor in " + name);
*/
//System.err.println("DefaultObjectFactory.create: successful");
            return Beans.create(type, args);
        } catch (ClassNotFoundException x) {
            throw x;
        }
    }
1073831
public String[] generateObjectNameCodes(final String objectName) {
        Objects.requireNonNull(objectName, "objectName should not be null");
        
        final List<String> codeList = new ArrayList<String>();
        codeList.add(objectName);
        
        // オブジェクト名の最後の値を取得する
        final int dotIndex = objectName.lastIndexOf('.');
        if(dotIndex > 0) {
            final String subName = objectName.substring(dotIndex + 1);
            codeList.add(subName);
            
        }
        
        return codeList.toArray(new String[codeList.size()]);
    }
974204
public static UsernameAttribute createUsernameAttribute(String username) {
		UsernameAttribute attribute = new UsernameAttribute();

		try {
			attribute.setUsername(username.getBytes("UTF-8"));
		} catch (UnsupportedEncodingException ueex) {
			throw new UndeclaredThrowableException(ueex);
		}
		return attribute;
	}
1317342
public Object makeObjectFromClassName(String className, String version, boolean bErrorIfNotFound) throws RuntimeException
    {
        if (className == null)
            return null;
        className = ClassServiceUtility.getFullClassName(className);

        Class<?> clazz = null;
        try {
            clazz = Class.forName(className);
        } catch (ClassNotFoundException e) {
            if (this.getClassFinder(null) != null)
                clazz = this.getClassFinder(null).findClass(className, version);	// Try to find this class in the obr repos
            if (clazz == null)
                if (bErrorIfNotFound)
                    throw new RuntimeException(e.getMessage());
        }

        Object object = null;
        try {
            if (clazz != null)
                object = clazz.newInstance();
        } catch (InstantiationException e)   {
            if (bErrorIfNotFound)
                throw new RuntimeException(e.getMessage());
        } catch (IllegalAccessException e)   {
            if (bErrorIfNotFound)
                throw new RuntimeException(e.getMessage());
        } catch (Exception e) {
            if (bErrorIfNotFound)
                throw new RuntimeException(e.getMessage());
        }
        return object;
    }
247606
public Class<?> forName(final String name) throws ClassNotFoundException {
        if (System.getSecurityManager() == null)
            return Class.forName(name);
        try {
            return AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>() {
                @Override
                public Class<?> run() throws Exception {
                    return Class.forName(name);
                }
            }, controlContext);
        } catch (PrivilegedActionException e) {
            if (e.getException() instanceof ClassNotFoundException)
                throw (ClassNotFoundException) e.getException();
            throw (RuntimeException) e.getException();
        }
    }
1364394
public static Object createObject(String classname) throws ParseException
    {
        Class<?> cl;

        try
        {
            cl = Class.forName(classname);
        }
        catch (ClassNotFoundException cnfe)
        {
            throw new ParseException("Unable to find the class: " + classname);
        }
        
        try
        {
            return cl.newInstance();
        }
        catch (Exception e)
        {
            throw new ParseException(e.getClass().getName() + "; Unable to create an instance of: " + classname);
        }
    }
65750
private VarNamePattern getValidVarNamePattern( String varNamePattern) throws IllegalArgumentException
    {
    VarNamePattern pattern = new VarNamePattern( varNamePattern);
    if( !pattern.isValid())
      {
      throw new IllegalArgumentException( "\"" + pattern + "\" is not a valid variable name pattern");
      }

    return pattern;
    }
454718
public static UsernameAttribute createUsernameAttribute(byte username[]) {
		UsernameAttribute attribute = new UsernameAttribute();

		attribute.setUsername(username);
		return attribute;
	}